//
//  UpdateAlertView.m
//  CouponsMerchantSideTwo
//
//  Created by jansh on 16/3/11.
//  Copyright © 2016年 jansh. All rights reserved.
//

#import "UpdateAlertView.h"

#define kScreenWidth [UIScreen mainScreen].bounds.size.width
#define kScreenHeight [UIScreen mainScreen].bounds.size.height

#define kWidth (kScreenWidth-20)
#define kHeight (kScreenHeight*0.3)

@implementation UpdateAlertView

- (instancetype)initWithEffect:(UIVisualEffect *)effect
{
    self = [super initWithEffect:effect];
    if (self) {
        [self addSubviews];
    }
    return self;
}

- (void)addSubviews
{
    self.bgView = [[UIView alloc] initWithFrame:CGRectMake(10, 10, (kScreenWidth-20), kScreenHeight*0.3)];
    self.bgView.backgroundColor = [UIColor whiteColor];
    self.bgView.layer.cornerRadius = 5;
    self.bgView.layer.masksToBounds = YES;
    self.bgView.center = CGPointMake(kScreenWidth/2, kScreenHeight/2);
    [self addSubview:_bgView];
    
    // 标题
    UILabel *titile = [[UILabel alloc] initWithFrame:CGRectMake(0, 5, kWidth, 50)];
    titile.text = @"软件版本更新";
    titile.textAlignment = NSTextAlignmentCenter;
    [self.bgView addSubview:titile];
    
    UIView *lineOne = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(titile.frame), kWidth, 1)];
    lineOne.backgroundColor = [UIColor lightGrayColor];
    [self.bgView addSubview:lineOne];
    
    // 要显示的内容 view
    _contentV = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(lineOne.frame), kWidth, 100)];
//    _contentV.backgroundColor = [UIColor redColor];
    [self.bgView addSubview:_contentV];
    
    UILabel *version = [[UILabel alloc] initWithFrame:CGRectMake(10, 5, CGRectGetWidth(self.contentV.frame)*0.225, 30)];
    version.text = @"版本名称:";
//    version.backgroundColor = [UIColor cyanColor];
    [self.contentV addSubview:version];
    
    _versionLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(version.frame), 5, CGRectGetWidth(self.contentV.frame) * 0.7, CGRectGetHeight(version.frame))];
    _versionLabel.text = @"1.0.1";
//    _versionLabel.backgroundColor = [UIColor orangeColor];
    [self.contentV addSubview:_versionLabel];
    
    UILabel *updateTime = [[UILabel alloc] initWithFrame:CGRectMake(10, CGRectGetMaxY(version.frame), CGRectGetWidth(version.frame), 30)];
//    updateTime.backgroundColor = [UIColor brownColor];
    updateTime.text = @"更新时间:";
    [self.contentV addSubview:updateTime];
    
    _updateLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(updateTime.frame), CGRectGetMaxY(version.frame), CGRectGetWidth(self.versionLabel.frame), 30)];
    _updateLabel.text = @"2016-3-11";
//    _updateLabel.backgroundColor = [UIColor lightGrayColor];
    [self.contentV addSubview:_updateLabel];
    
    UILabel *updateLog = [[UILabel alloc] initWithFrame:CGRectMake(10, CGRectGetMaxY(updateTime.frame), CGRectGetWidth(version.frame), 30)];
    updateLog.text = @"更新日志:";
//    updateLog.backgroundColor = [UIColor greenColor];
    [self.contentV addSubview:updateLog];
    
    _updateLogLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(updateLog.frame), CGRectGetMaxY(updateTime.frame), CGRectGetWidth(self.versionLabel.frame), 30)];
    _updateLogLabel.numberOfLines = 0;
    _updateLogLabel.textAlignment = NSTextAlignmentLeft;
//    _updateLogLabel.text = @"新增二维码扫描功能,跳转到网页客户端功能,修复项目中出现的bug";
//    _updateLogLabel.backgroundColor = [UIColor magentaColor];
    [self.contentV addSubview:_updateLogLabel];
    
    _lineTwo= [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.contentV.frame), kWidth, 1)];
    _lineTwo.backgroundColor = [UIColor lightGrayColor];
    [self.bgView addSubview:_lineTwo];
    
    _updateButton = [UIButton buttonWithType:UIButtonTypeCustom];
    _updateButton.frame = CGRectMake(0, CGRectGetMaxY(self.lineTwo.frame)*1.02, kWidth/2, 30);
//    [_updateButton setBackgroundColor:[UIColor whiteColor]];
    [_updateButton setTitleColor:[UIColor blackColor] forState:(UIControlStateNormal)];
    [_updateButton setTitle:@"立即更新" forState:(UIControlStateNormal)];
    [self.bgView addSubview:_updateButton];
    
    _lineThree = [[UIView alloc] initWithFrame:CGRectMake(CGRectGetMaxX(self.updateButton.frame), CGRectGetMaxY(self.contentV.frame), 1, CGRectGetHeight(self.bgView.frame)- CGRectGetMaxY(self.lineTwo.frame))];
    _lineThree.backgroundColor = [UIColor lightGrayColor];
    [self.bgView addSubview:_lineThree];
    
    _resignButton = [UIButton buttonWithType:UIButtonTypeCustom];
    _resignButton.frame = CGRectMake(CGRectGetMaxX(self.lineThree.frame), CGRectGetMaxY(self.lineTwo.frame)*1.02, kWidth/2-1, 30);
//    [_resignButton setBackgroundColor:[UIColor yellowColor]];
    [_resignButton setTitleColor:[UIColor blackColor] forState:(UIControlStateNormal)];
    [_resignButton setTitle:@"以后再说" forState:(UIControlStateNormal)];
    [_resignButton addTarget:self action:@selector(resignButtonAction:) forControlEvents:(UIControlEventTouchUpInside)];
    [self.bgView addSubview:_resignButton];
}


- (void)resignButtonAction:(UIButton *)sender
{
    [self removeFromSuperview];
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
